package com.example.mapper;
import com.example.entity.Order;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    @Select("select * from `order` where order_id=#{order_id}")
    Order findByOrderid(String order_id);
    void updata(Order order);
    @Insert("insert into `order` (order_timestart, table_id, customer_id, type,order_timefinish,order_num) values (#{orderTimestart}, #{tableId}, #{customerId}, #{type},#{orderTimefinish},#{orderNum})")
    @Options(useGeneratedKeys = true, keyProperty = "orderId")
    int insert(Order order);
    @Delete("DELETE FROM `order` WHERE order_id = #{order_id}")
    void delete(String order_id);
    @Select("SELECT * FROM `order` WHERE table_id = #{tableId} AND order_timefinish IS NULL")
    Order findByOrdertableId(String tableId);



    List<Order> orderList(Integer page, Integer pageSize, String query);
    @Select("SELECT * FROM `order` WHERE customer_id = #{customerId} AND order_timefinish IS NOT NULL")
    List<Order> orderListById(String customerId);
    @Select("SELECT * FROM `order` WHERE customer_id = #{customerId} AND order_timefinish IS  NULL")
    List<Order> orderListByIdNo(String customerId);
    long orderTotal(Integer page, Integer pageSize, String query);
    @Select("SELECT * FROM `order` WHERE order_timestart >= #{fiveSecondsAgo} AND order_timestart <= #{currentTime}")
    List<Order> getOrdersInTimeRange(LocalDateTime fiveSecondsAgo, LocalDateTime currentTime);
}
